;$(function () {
    // 点击发送
    $('#btnSend').on('click', function (e) {
        const text = $('#ipt').val().trim()
        if (text.length == 0) return $('#ipt').val('')
        const li = `<li class="right_word">
        <img src="img/person02.png" /> <span>${text}</span>
      </li>`
        $('#talk_list').append(li)
        $('#ipt').val('')
        resetui()
        getMsg(text)
    })
    // 回车发送
    document.body.addEventListener('keyup', function (e) {
        if (e.key === 'Enter') {
            $('#btnSend').click()
        }
    })
    // 获取聊天数据
    function getMsg(text) {
        $.ajax({
            type: "get",
            url: 'http://www.liulongbin.top:3006/api/robot',
            data: {
                spoken: text
            },
            success: function (response) {
                const msg = response.data.info.text
                video(msg)
                if (response.message === 'success') {
                    const li = `<li class="left_word">
                    <img src="img/person01.png" /> <span>${msg}</span>
                  </li>`
                    $('#talk_list').append(li)
                }
                resetui()
            }
        });
    }
    // 获取语音src
    function video(msg) {
        $.ajax({
            type: "get",
            url: 'http://www.liulongbin.top:3006/api/synthesize',
            data: {
                text: msg
            },
            success: function (response) {
                if (response.status == 200) {
                    $('#voice').attr('src', response.voiceUrl)
                }
            }
        });
    }
});